import { PropType, defineComponent } from 'vue';
import { hasPermission } from './utils';

export const WithPermission = defineComponent({
  props: {
    code: {
      type: String as PropType<string | string[]>,
    },
  },
  setup(props, { slots }) {
    if (props.code && hasPermission(props.code)) {
      return () => <>{slots.default?.() || null}</>;
    } else {
      return () => <></>;
    }
  },
});
